package day_2022_7_to_8.day48;
import java.util.*;
/**
 * @author haomin
 * @date 2022/08/28 22:56
 **/
public class Day43_7_Num49_GroupAnagrams {
    class Solution {
        public List<List<String>> groupAnagrams(String[] strs) {
            Map<String, List<String>> map = new HashMap<>();
            for(String s : strs){
                char[] ch = s.toCharArray();
                Arrays.sort(ch);
                String key = String.valueOf(ch);
                if(!map.containsKey(key)) map.put(key, new ArrayList<>());
                map.get(key).add(s);
            }
            return new ArrayList(map.values());
        }
    }
}